import { renderRegistry } from './registShape.js'
import { _labels } from './polygon.js'
import { _path2 } from './path2.js'
import { _merge } from '../common/index.js'
const renderPath = (points, options, props) => {
    return _path2({
        ...options,
        points
    },
        _merge({
            stroke: 'blue',
            fill: 'none',
        }, props)
    )
}

const renderUnregistry = (options) => {
    let { shape, o } = options
    // 提示未注册shape
    let label = `未注册${shape}`
    let labels = _labels({
        points: [o],
        label
    }, {}, {
        'font-size': '20px'
    }
    )
    return labels
}

export const renderShape = (options, props) => {
    let {
        name,
        shape,
        pattern,
        points
    } = options

    // 填充图案
    if (pattern) {
        props = {
            ...props,
            fill: `url(#${name}_${pattern})`
        }
    }


    let registry = renderRegistry(shape, options, props)
    if (registry) {
        return registry
    } else {
        if (points) {
            //         if (isCurve(shape)) {
            //             // 曲线函数
            //             points = _curve(points, options)
            //         }
            return renderPath(points, options, props)
        } else {
            return renderUnregistry(options)

        }
    }
}